package datastructure;

public class MyArray {
    public int length;
    public int elements;
    public int[] array;

    public MyArray() {
        this.length = 10;
        this.array = new int[length];
    }

    public MyArray(int length) {
        this.length = length;
        this.array = new int[length];
    }

    public boolean add(int val) {
        if(elements == length) {
            return false;
        }
        array[elements++] = val;
        return true;
    }

    public void display() {
        for (int i = 0; i < elements; i++) {
            System.out.print(array[i]);
        }
        System.out.println();
    }

    public boolean remove(int val) {
        int i;
        for (i = 0; i < elements; i++) {
            if (val == array[i]) {
                array[i] = 0;
                break;
            }
        }
        if(i==elements) {return false;}
        for (int j = i; j < elements-1; j++) {
            array[j] = array[j+1];
        }
        elements--;
        return true;
    }
}
